package intetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo {

	public static void main(String[] args) {
		 
        new InetAddressDemo().getRomtePcIp();

	}
	
	private void test(){
		try{

            //使用域名创建对象

            InetAddress inet1 = InetAddress.getByName("www.163.com");

            System.out.println(inet1);

            //使用IP创建对象

            InetAddress inet2 = InetAddress.getByName("127.0.0.1");

            System.out.println(inet2);

            //获得本机地址对象

            InetAddress inet3 = InetAddress.getLocalHost();

            System.out.println("3="+inet3);

            //获得对象中存储的域名

            String host = inet3.getHostName();

            System.out.println("域名：" + host);

            //获得对象中存储的IP

            String ip = inet3.getHostAddress();

            System.out.println("IP:" + ip);

   }catch(Exception e){}
	}
	
	private void getRomtePcIp(){
		try {
//			InetAddress inet2 = InetAddress.getByName("192.168.1.103");
//			System.out.println(inet2.getHostName()+"|"+inet2.getHostAddress());
			
			String ipHead="172.18.0.";
			for(int i=178;i<255;i++){
				String nowCmd=ipHead+i;
				System.out.println(nowCmd);
				InetAddress inet2 = InetAddress.getByName(nowCmd);
				System.out.println(inet2.getHostName()+"|"+inet2.getHostAddress());
			}
			
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

        
		
	}
	

	
}
